<?php
/**
 * 店铺控制器
 * 
 * @version $Id: Shop.php 487 2012-11-05 07:33:54Z linsir123 $
 */
class controllerShop extends AppController 
{
	/**
	 * @var 模型
	 */
	public $mItem;
	
	/**
	 * @var 模型
	 */
	public $mShop;
	
	/**
	 * @var 模型
	 */
	public $mNav;
	
	/**
	 * 构造函数
	 */
	public function __construct()
	{
		parent::__construct();
		
		///
		$this->mItem = M::item();
		$this->mNav = M::nav();
		$this->mShop = M::shop();
		
		///
		AppView::addJs('colorbox/colorbox/jquery.colorbox.js');
		AppView::addCss('javascript/colorbox/example5/colorbox.css');
	}
	
	/**
	 * 商铺
	 */
	public function actionInfo()
	{
		$nick = $this->_getNick();
		
		///
		$shop = $this->mShop->getOne($nick);
		if (empty($shop)) 
			$this->miss();
			
		///
		$items = $this->mItem->getPShop($shop['user']['user_id']);
		$shops = $this->mShop->getRelate($nick);
		$keyMeta = $shop['nick'];
		foreach ($shops as $v) 
			$keyMeta .= ",". $v['nick'];
			
		///
		View::display('shop/index');
		View::assignSet(array(
			'shop' => $shop, 
			'shops' => $shops, 
			'items' => $items, 
			'keyMeta' => $keyMeta
		));
		
		///
		AppView::addCss('themes/01/shop.css');
	}
	
	/**
	 * 页面跳转
	 */
	public function actionJump()
	{
		$nick = $this->_getNick();
		$uId = empty(M::user()->uId) ? '' : M::user()->uId;
		
		///
		View::display('shop/jump');
		View::assignSet(array(
			'nick' => $nick,
			'uId' => $uId
		));
	}
	
	
	/// 以下为私有方法 ///
	
	
	/**
	 * 取得店铺呢称
	 */
	private function _getNick()
	{
		$nick = trim($_GET['nick']);
		
		///
		if ( ! empty($nick)) {
			$tmp = iconv("UTF-8", "UTF-8", $nick);
			if ($tmp != $nick) 
				$nick = iconv("GBK", "UTF-8", $nick);
		}
		
		return $nick;
	}
}
